package com.alks.function.controller.produce;


import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.common.utils.beanutils.ObjectUtils;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.chengKong.LotNoToStyleRequest;
import com.alks.function.data.request.produce.deleteRequest;
import com.alks.function.data.request.produce.dispatchHeadRequest;
import com.alks.function.data.request.produce.doDispatchRequest;
import com.alks.function.service.produce.CuttingDispatchHeadService;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@ApiRestController("/cut/plan/dispatch")
@Api(tags ={ "生产部-生产作业-生产派工-冲裁派工"})
@Slf4j
public class CuttingDispatchHeadController {

    @Autowired
    private CuttingDispatchHeadService cuttingDispatchHeadService;

    @WebLogger
    @PostMapping("/dispatchHeadList")
    @ApiOperation(value = "冲裁派工查询",tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo dispatchHeadList(@RequestBody dispatchHeadRequest request){
        return cuttingDispatchHeadService.dispatchHeadList(request);
    }

    @WebLogger
    @PostMapping("/dispatchDetailList")
    @ApiOperation(value = "派工号码明细",tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo dispatchDetailList(@RequestBody dispatchHeadRequest request){
        return cuttingDispatchHeadService.dispatchDetailList(request);
    }

    @WebLogger
    @PostMapping("/tree/list")
    @ApiOperation(value = "插入派工资料-冲裁派工查询", tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo loadCutLabelTree(@RequestParam String lotNo, @RequestParam List<String> lsNos) {
        return cuttingDispatchHeadService.loadCutLabelTree(lotNo, lsNos);
    }

    @WebLogger
    @PostMapping("/lot/page")
    @ApiOperation(value = "插入派工资料-选择指令", tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo loadCuttingCheckerList(@RequestBody LotNoToStyleRequest request) {
        return cuttingDispatchHeadService.loadCuttingCheckerList(request);
    }

    @WebLogger
    @PostMapping("/lsNo/list")
    @ApiOperation(value = "插入派工资料-查询轮次", tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo loadLsNoByLotNo(@RequestParam String lotNo) {
        return cuttingDispatchHeadService.loadLsNoByLotNo(lotNo);
    }

    @WebLogger
    @PostMapping("/combine/sizeNoCombo")
    @ApiOperation(value = "插入派工资料-号码查询", tags = "生产部-生产作业-生产派工-冲裁派工")
    public List<Map<String, String>> loadCombineDispatchSizeNo(@RequestParam String lotNo, @RequestParam List<String> lsNos) {
        return cuttingDispatchHeadService.loadCombineDispatchSizeNo(lotNo, lsNos);
    }

    @WebLogger
    @PostMapping("/loadCuttingCheckerList2")
    @ApiOperation(value = "插入派工资料-当日冲工点检信息查询", tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo loadCuttingCheckerList2(@RequestParam@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate dispatchDate, @RequestParam String cutWorkerName) {
        return cuttingDispatchHeadService.loadCuttingCheckerList2(dispatchDate, cutWorkerName);
    }

    @WebLogger
    @PostMapping("/cutWorkerDispatchHeadList")
    @ApiOperation(value = "插入派工资料-查看派工明细", tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo cutWorkerDispatchHeadList(@RequestParam@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate dispatchDate, @RequestParam String workerId) {
        return cuttingDispatchHeadService.cutWorkerDispatchHeadList(dispatchDate, workerId);
    }

    @WebLogger
    @PostMapping("/doDispatch")
    @ApiOperation(value = "插入派工资料-插入", tags = "生产部-生产作业-生产派工-冲裁派工")
    public  ResponseInfo doDispatch(@RequestBody doDispatchRequest request){
        return cuttingDispatchHeadService.doDispatch(request);
    }

    @WebLogger
    @PostMapping("/delete")
    @ApiOperation(value = "删除", tags = "生产部-生产作业-生产派工-冲裁派工")
    public  ResponseInfo deleteByDispatchNo(@RequestBody List<deleteRequest> request){
        return cuttingDispatchHeadService.deleteByDispatchNo(request);
    }

    @WebLogger
    @PostMapping({"/summary/print"})
    @ApiOperation(value = "打印汇总表", tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo summaryPrint(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") LocalDate beginDate, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") LocalDate endDate) {
        return cuttingDispatchHeadService.summaryPrint(beginDate, endDate);
    }

    @WebLogger
    @PostMapping({"/label/print"})
    @ApiOperation(value = "打印轮次标签(按搜索条件)", tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo printLabel(@RequestBody dispatchHeadRequest request){
        if (ObjectUtils.isEmpty(request.getSlipDateStart())||ObjectUtils.isEmpty(request.getSlipDateEnd())){
            return ResponseInfo.error("时间不能为空!");
        }
        return cuttingDispatchHeadService.printLabel(request);
    }

    @WebLogger
    @PostMapping({"/label/un/print"})
    @ApiOperation(value = "打印轮次标签(未打印)", tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo UnPrintLabel(){
        return cuttingDispatchHeadService.UnPrintLabel();
    }

    @WebLogger
    @PostMapping({"/combine/print"})
    @ApiOperation(value = "打印派工单", tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo planNoCombinePrint(@RequestParam String planNo){
        return cuttingDispatchHeadService.planNoCombinePrint(planNo);
    }

    @WebLogger
    @PostMapping({"/combine/label/print"})
    @ApiOperation(value = "打印标签", tags = "生产部-生产作业-生产派工-冲裁派工")
    public ResponseInfo printCombineLabel(@RequestParam String planNo){
        return cuttingDispatchHeadService.printCombineLabel(planNo);
    }
}
